﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerObject : SlotObject
{
    public AudioSource moveAudio;
    // Start is called before the first frame update
    protected new void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    void OnDestroy()
    {
        slot.gridManager.Player.GameOver();
    }

    public override bool Move(int dx, int dy, float duration = 0.4f) {
        Slot newSlot = slot.GetNewSlot(dx, dy);
        if(newSlot == null)
            return false;
        if(newSlot.SlotState == Slot.State.none || newSlot.SlotState == Slot.State.boss1)
            return false;
        if(newSlot.SlotObject != null) {
            if(!newSlot.SlotObject.OnPlayerTouch(slot.gridManager.Player, dx, dy))
                return false;
        }
        moveAudio.Play();
        base.Move(dx, dy, duration);
        slot.SlotState = Slot.State.player;
        return true;
    }

    public override bool OnPlayerTouch(Player player, int dx = 0, int dy = 0) {
        Debug.Log("Error! Player on player touch!");
        return true;
    }
}
